package com.vf.admin.miaodong.controller.org;

import cn.hutool.core.util.ObjectUtil;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.vf.admin.client.service.AppMingxiJinbiService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.miaodong.service.AfterUserService;
import com.vf.admin.platform.dto.OrgUserDto;
import com.vf.admin.platform.entity.User;
import com.vf.admin.platform.service.UserService;
import com.vf.admin.utils.StringEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.Inflater;

import static com.vf.admin.common.Constants.guizuMingMap;
import static com.vf.admin.utils.StringEx.isNull;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/10/11 10:00
 */
@Controller
@RequestMapping("/after/org")
public class OrgUserController extends BaseController {


    @Resource
    private UserService userService;
    @Autowired
    AfterUserService afterUserService;
    @Autowired
    private AppMingxiJinbiService appMingxiJinbiService;

    /**
     * 获取工会列表
     *
     * @param splitPageBean
     * @return
     */
    @RequestMapping("/orgList")
    public String userList(SplitPageBean splitPageBean, String time) {
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("time", time);
            List<OrgUserDto> orgUserDtoList = userService.getOrgUserDtoList(map, time, splitPageBean);
            request.setAttribute("list", orgUserDtoList);
            request.setAttribute("time", time);
            request.setAttribute("splitPage", splitPageBean);
            return this.sucess("/web/after/org/orgList");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error("系统繁忙");
        }
    }


    /**
     * 打开工会底下列表
     */
    @RequestMapping("/detailList")
    public String detailList(String code, SplitPageBean splitPage, String loginname, String startDate,
                             String endDate, Integer states, String nick,
                             Integer onlineStatus, Integer windowTicket, Integer vipStatus) {

        try {
            Map<String, Object> map = new HashMap<>();

            if (ObjectUtil.isNotEmpty(code)) {
                map.put("invitationcode", code);
            } else {
                map.put("invitationcode", "abcxdadasd");
            }
            map.put("loginname", loginname);
            map.put("startDate", startDate);
            map.put("endDate", endDate);
            map.put("states", states);
            map.put("nick", nick);
            map.put("onlineStatus", onlineStatus);
            map.put("windowTicket", windowTicket); //
            map.put("vipStatus", vipStatus); //
            List<AppUser> maps = afterUserService.findList(map, splitPage);
            for (AppUser user : maps) {
                user.setGuizuname(isNull(user.getNobleid()) || user.getNobleid() > 0 ? guizuMingMap.get(user.getNobleid()) : "");

            }
            Map<Integer, String> sexMap = Constants.getSexMap();
            Map<Integer, String> statesMap = Constants.getStatesMap();
            //在线状态
            Map<Integer, String> onlineStatusMap = Constants.getOnlineStatusMap();
            //
            Map<Integer, String> windowTicketMap = Constants.getWindowsTicketMap();
            //
            Map<Integer, String> vipStatusMap = Constants.getVipStatusMap();

            request.setAttribute("code", code);
            request.setAttribute("loginname", loginname);
            request.setAttribute("startDate", startDate);
            request.setAttribute("endDate", endDate);
            request.setAttribute("list", maps);
            request.setAttribute("sexMap", sexMap);
            request.setAttribute("splitPage", splitPage);
            request.setAttribute("statesMap", statesMap);
            request.setAttribute("onlineStatusMap", onlineStatusMap);
            request.setAttribute("states", states);
            request.setAttribute("onlineStatus", onlineStatus);
            request.setAttribute("nick", nick);
            request.setAttribute("windowTicketMap", windowTicketMap);
            request.setAttribute("windowTicket", windowTicket);
            request.setAttribute("vipStatusMap", vipStatusMap);
            request.setAttribute("vipStatus", vipStatus);
            return this.sucess("/web/after/org/detailList");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error("系统繁忙");
        }
    }


    /**
     * 礼物列表
     */
    @RequestMapping("/giftList")
    public String giftList(Integer id, SplitPageBean splitPage) {

        try {
            Map<String, Object> map = new HashMap<>();
            map.put("userId", id);
            map.put("beizhu", "礼物收入");//关键字

            List<AppMingxiJinbi> info = appMingxiJinbiService.orgInfo(map, splitPage);
            List<AppMingxiJinbi> count = appMingxiJinbiService.countNum(map);

            double sum = count.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();
            BigDecimal p1 = new BigDecimal(Double.toString(sum));
            request.setAttribute("count", p1);
            request.setAttribute("splitPage", splitPage);
            request.setAttribute("list", info);
            request.setAttribute("userid",  id);
            return this.sucess("/web/after/org/giftList");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error("系统繁忙");
        }
    }


    /**
     * 礼物列表
     */
    @RequestMapping("/mvList")
    public String mvList(Integer id, SplitPageBean splitPage) {

        try {
            Map<String, Object> map = new HashMap<>();
            map.put("userId", id);
            map.put("beizhu", "语音消息收入,视频消息收入");//关键字

            List<AppMingxiJinbi> info = appMingxiJinbiService.orgInfo(map, splitPage);
            List<AppMingxiJinbi> count = appMingxiJinbiService.countNum(map);
            double sum = count.stream().mapToDouble(e -> Double.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();
            BigDecimal p1 = new BigDecimal(Double.toString(sum));
            request.setAttribute("count",  p1);
            request.setAttribute("userid",  id);
            request.setAttribute("splitPage", splitPage);
            request.setAttribute("list", info);
            return this.sucess("/web/after/org/mvList");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error("系统繁忙");
        }
    }

}
